package com.unf.edu.rms.controller.validation;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.unf.edu.rms.controller.users.UsersController;
import com.unf.edu.rms.dao.UserLogin;

public class UserValidator implements Validator{

	@Override
	public boolean supports(Class<?> arg0) {
		return UsersController.class.equals(arg0);
		
	}

	@Override
	public void validate(Object obj, Errors errors) {
		System.out.println("UserLoginValidator.validate()==============");
		UserLogin user = (UserLogin)obj;
		
		if(user.getUserRole().getUserRoleId()==0){
			errors.rejectValue("userRole.userRoleId", "error.userrole.required");
		}
		ValidationUtils.rejectIfEmpty(errors, "faculty.facultyId", "error.facultyid.required");
		ValidationUtils.rejectIfEmpty(errors, "userName", "error.username.required");
		ValidationUtils.rejectIfEmpty(errors, "password", "error.password.required");
	}
}
